home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17021 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: ix.netcom.com!news
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: const member functions
  5. Date: Fri, 12 Apr 1996 18:10:51 GMT
  6. Organization: Netcom
  7. Message-ID: <316e9bef.157471972@nntp.ix.netcom.com>
  8. References: <316588E6.7D61@geoplex.com> <4kgs7s$vb4@zk2nws.zko.dec.com>
  9. NNTP-Posting-Host: ix-dc11-06.ix.netcom.com
  10. X-NETCOM-Date: Fri Apr 12  1:07:44 PM CDT 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. Alexander Goykhman USG <goykhman@zk3.dec.com> wrote:
  14.  
  15. > "Jay B. Perry" <jay@geoplex.com> wrote:
  16. > >class X 
  17. > >{
  18. > >public:   //  Public methods
  19. > >   int value( ) const { return _value; }
  20. > >
  21. > >private:  //  Private methods
  22. > >
  23. > >   int& value( ) { return _value; }
  24. >     I don't see how a compiler could possibly 
  25. >         distinguish between:
  26. >         int value() 
  27. >     and
  28. >         int& value() 
  29. >     IMO, the above is ambiguous and ought to be
  30. >     flagged as such by the compiler.
  31.  
  32. Non seqitur.  The compiler cannot distinquish between
  33.  
  34.     int value()
  35.  
  36. and
  37.  
  38.     int& value()
  39.  
  40. and any correct compiler will flag that as an error.
  41.  
  42. However, that has nothing to do with the code Jay posted where he asks
  43. the compiler to distinguish between
  44.  
  45.     int value()
  46.  
  47. and
  48.  
  49.     int& value() const
  50.  
  51. C++ allows overloading based on whether the class object is const.
  52.  
  53.  
  54. Michael M Rubenstein
  55.